<?php
include 'config.php';
include "functions.$phpEx";
include "ForumTools.$phpEx";

connectDataBase();

$sitename = ForumTools::Sitename();
$sitedesc = ForumTools::Description();
$sitelink = ForumTools::Link();					?>
<?='<?'?>xml version="1.0" encoding="UTF-8"<?='?>'?>
<rss version="2.0">
	<channel>
		<title><?=$sitename?> (Last Posts)</title>
		<link><?=$sitelink?></link>
		<description><?=$sitedesc?></description>
		<category>Last Posts</category>
<?php
$sql = "SELECT	{$table_prefix}posts.*,
		{$table_prefix}forums.forum_name,
		{$table_prefix}users.user_avatar
	FROM	{$table_prefix}posts,
		{$table_prefix}forums,
		{$table_prefix}users
	WHERE	{$table_prefix}posts.forum_id  = {$table_prefix}forums.forum_id
	 AND	{$table_prefix}posts.poster_id = {$table_prefix}users.user_id
	ORDER BY {$table_prefix}posts.post_time DESC";
$res = $db->sql_query_limit($sql, $postsLimitOnRSS);

while ($row = $db->sql_fetchrow($res)) {					?>
		<item>
			<title><?=$row['post_subject']?></title>
			<link><?=ForumTools::AdaptString("{$sitelink}/viewtopic.php?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}")?></link>
			<description><?=ForumTools::AdaptString($row['post_text'], true)?></description>
			<category><?=$row['forum_name']?></category>
<?php	if ($row['user_avatar']) {						?>
			<image><?=$row['user_avatar']?></image>
<?php	}									?>
		</item>
<?php	
}

$db->sql_freeresult($res);							?>
	</channel>
</rss>